
#ifndef   __INTERNAL_FLASH_MEM__
#define   __INTERNAL_FLASH_MEM__

#include "Sys.h"
#include "sys_config.h"

#define   GO_TO_MAIN_PROG			0x12345678

#define   FM_ADDR_START				0x0007D000
#define   F_MEM_SIZE					1024


/* Flash Memory Mapping; all addresses is relative of FM_ADDR_START  */
#define   FM_ADDR_BOOT					0

#define  ERR_NO_ERR               0
#define  ERR_WRONG_PARAM          1
#define  ERR_WSTATE               2


#define  FWU_INTSAVE_DATA         int save_status_reg = 0;
#define  fwu_disable_interrupt()  save_status_reg = cpu_save_sr()
#define  fwu_enable_interrupt()   cpu_restore_sr(save_status_reg)


#define  IAP_CMD_PREPARE_SECTORS               50
#define  IAP_CMD_COPY_RAM_TO_FLASH             51
#define  IAP_CMD_ERASE_SECTORS                 52

#define  IAP_CMD_SUCCESS                        0
#define  IAP_BUSY                              11

//#define  IAP_LOCATION             0x7ffffff1

unsigned int iap_command(unsigned int cmd,
                                unsigned int p0,
                                unsigned int p1,
                                unsigned int p2,
                                unsigned int p3,
                                unsigned int *r0);


/*  */

int fm_Erase ( void );

int fm_check_boot (void);

#endif
